package com.tjh.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * day117：订单确认页需要用到的数据VO
 * Create by koala on 2021-05-17
 */
public class OrderConfirmVo {
    @Setter@Getter
    private List<MemberAddressVo> address;//收货地址列表
    @Setter@Getter
    private List<OrderItemVo> items;//所有选中的购物项

    //发票记录……

    //优惠券信息……
    @Setter@Getter
    private Integer integration;//此处只查积分信息

    @Setter@Getter
    private String orderToken;//防重令牌

    private Integer count;
    @Setter@Getter
    Map<Long,Boolean> stocks;//是否有库存

    //private BigDecimal total;//订单总额
    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal("0");
        if (items!=null && items.size()>0) {
            for (OrderItemVo item:items){
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //private BigDecimal payPrice;//应付价格

    public BigDecimal getPayPrice(){
        return getTotal();
    }

    public Integer getCount(){
        Integer i=0;
        if (items!=null&&items.size()>0){
            for (OrderItemVo itemVo:items){
                i+=itemVo.getCount();
            }
        }
        return i;
    }
}
